package com.management.commons.exception;

import com.management.utils.Result;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalException {

    @ExceptionHandler(DmBigException.class)
    public Result HandlerWoniuException(DmBigException e){
        return Result.getInstance().setCode(e.getCode()).setMessage(e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Result HandlerException(Exception e){
        e.printStackTrace();

        return Result.getInstance().setCode(500).setMessage("服务器繁忙");
    }
    @ExceptionHandler(MethodArgumentNotValidException.class)
    public Result HandleMethodArgumentNotValidException(MethodArgumentNotValidException e){
        return Result.getInstance().setCode(700).setMessage("参数校验未通过");
    }
}
